﻿using Lync.Widget.Library.Presentation.Models;
using Lync.Widget.Library.Presentation.Views;

namespace Lync.Widget.Library.Presentation.Presenters
{
    public class GroupMembersPresenter : IGroupMembersPresenter
    {
        public IGroupMembersView View { get; set; }
        public IGroupsModel Model { get; set; }

        public GroupMembersPresenter(IGroupMembersView view, IGroupsModel model)
        {
            View = view;
            Model = model;
        }

        public void Load(string organisationUnit, string distinguishedName)
        {
            View.OrganisationUnit = organisationUnit;
            View.GroupName = distinguishedName;

            if (!string.IsNullOrEmpty(View.GroupName) && !string.IsNullOrEmpty(View.OrganisationUnit))
            {
                var members = Model.GetGroupMembers(View.OrganisationUnit, View.GroupName);

                if (members != null && members.Count > 0)
                {
                    View.Members = members;                    
                }
            }
        }
    }
}